import { request } from '../../request'

/**
 * 获取草稿列表
 */
export function fetchDraftList(params: any) {
  return request.get<ApiModels.PageList<ApiModels.weixin.Material>>('/weixin/drafts/list', { params })
}

/**
 * 获取草稿详情
 */
export function fetchDraftDetail(mediaId: string) {
  return request.get<ApiModels.weixin.DraftModel[]>(`/weixin/drafts/get?mediaid=${mediaId}`)
}

/**
 * 创建草稿
 */
export function createDraft(draftList: ApiModels.weixin.NewsMaterialModelBase[]) {
  return request.post<{ mediaid: string }>('/weixin/drafts/create', draftList)
}

/**
 * 编辑更新某一篇草稿，用index指定，单个时 index=0
 */
export function updateDraft(mediaId: string, index: number, draft: ApiModels.weixin.DraftModel) {
  return request.put(`/weixin/drafts/update?mediaId=${mediaId}&index=${index}`, draft)
}

/**
 * 删除草稿
 */
export function deleteDraft(mediaId: string) {
  return request.delete(`/weixin/drafts/delete?mediaId=${mediaId}`)
}

/**
 * 群发草稿消息
 */
export function batchSendDraft(mediaId: string) {
  return request.post<{ msgId: string }>(`/weixin/drafts/batchSendMessage?mediaId=${mediaId}`)
}

/**
 * 发布草稿
 */
export function publishDraft(mediaId: string) {
  return request.post<{ publishid: string }>(`/weixin/drafts/publish?mediaId=${mediaId}`)
}
